<template>
    <div class="page_banner">
        <div class="page_banner-img">
            <img :src="bannerImg" class="animate__animated" />
        </div>
        <el-breadcrumb
            v-if="mainTitle"
            :separator-icon="ArrowRight"
            class="page_banner-breadcrumb maxWidth1400"
        >
            <el-breadcrumb-item :to="{ path: '/' }">
                <el-icon size="20" color="#ffffff"> <HomeFilled /> </el-icon
            ></el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/news/group' }">{{
                props.mainTitle
            }}</el-breadcrumb-item>
            <el-breadcrumb-item>{{ breadTitleCom }}</el-breadcrumb-item>
        </el-breadcrumb>
        <slot />
    </div>
    <div class="page_banner-menu" v-if="mainTitle">
        <div class="maxWidth1400">
            <ul>
                <li
                    :class="{
                        isActive:
                            item.key === route.query.key ||
                            item.key === route.params.slug,
                    }"
                    v-for="item in tabList"
                    :key="item.key"
                >
                    <a @click="navigateTo(item)">{{ item.title() }}</a>
                </li>
            </ul>
        </div>
    </div>
</template>

<script setup>
import { ArrowRight, HomeFilled } from "@element-plus/icons-vue";

const route = useRoute();
const router = useRouter();

// 定义 props
const props = defineProps({
    tabList: {
        type: Array,
        default: () => [],
    },
    bannerImg: {
        type: String,
        required: true,
        default: () => "",
    },
    mainTitle: {
        type: String,
        default: () => "",
    },
});
const navigateTo = (item) => {
    router.push({
        path: item.path,
        query: { key: item.key },
    });
};

const breadTitleCom = computed(() => {
    const result = props.tabList.find((item) => item.path === route.path);
    return result?.title() || "";
});
</script>

<style lang="scss" scoped>
.page_banner {
    position: relative;
    &-img {
        overflow: hidden;
        img {
            width: 100%;
            animation-name: imgScale;
            animation-duration: 1.5s;
        }
    }

    &-breadcrumb {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 35px;
        margin: 0 auto;
        display: flex;
        .el-breadcrumb__item {
            &::v-deep(.el-breadcrumb__inner) {
                cursor: pointer;
                color: #fff;
                transition: all 0.5s ease;
                font-size: 16px;
                font-weight: normal;

                &:hover {
                    color: var(--color-primary);
                }
            }

            &::v-deep(.el-breadcrumb__separator) {
                color: #fff;
            }
        }
    }
}
.page_banner-menu {
    position: sticky;
    top: 100px;
    height: 80px;
    z-index: 8;
    box-shadow: 0px 9px 13px 0px rgba(107, 107, 107, 0.15);
    background: #fff;

    ul {
        display: flex;
        align-items: center;

        li {
            // line-height: 80px;
            width: 33.33%;
            height: 80px;
            transition: all 0.5s ease;
            position: relative;
            cursor: pointer;

            a {
                width: 100%;
                text-align: center;
                position: relative;
                color: #999;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                &::after {
                    position: absolute;
                    content: "";
                    width: 1px;
                    height: 40px;
                    background: var(--color-primary);
                    top: 20px;
                    right: 0;
                }
            }

            &::before {
                content: "";
                position: absolute;
                width: 100%;
                height: 0;
                opacity: 0;
                background: #ffc600;
                left: 0;
                bottom: 0;
                z-index: -1;
                transition: all 0.5s ease;
            }
        }

        li:last-child {
            a {
                &::after {
                    display: none;
                }
            }
        }

        li.isActive,
        li:hover {
            &::before {
                color: #fff;
                background-color: var(--color-primary);
                height: calc(100% + 8px);
                opacity: 1;
            }

            a {
                color: #fff;
            }
        }
    }
}

@keyframes imgScale {
    0% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}
@media screen and (max-width: 1200px) {
    .page_banner-menu {
        height: 60px;
        top: 80px;
        ul li {
            height: 60px;
            a::after {
                height: 40px;
                top: 10px;
            }
        }
    }
}
</style>
